package top.zhangjianyong.tools.etf;

import lombok.Data;
import top.zhangjianyong.tools.entity.ETF;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author ： zhangjianyong
 * @date ： 2022/12/22 4:32 PM
 */
@Data
public class ETFHoldInfo {
    private ETF etf;
    private BigDecimal unit;//持有份额
    private BigDecimal buyMoney;//购入总额

    private BigDecimal value;

    public ETFHoldInfo(ETF etf) {
        this.etf = etf;
        this.unit = BigDecimal.ZERO;
        this.buyMoney = BigDecimal.ZERO;
    }

    public BigDecimal rate(BigDecimal value) {
        if (buyMoney.compareTo(BigDecimal.ZERO) == 0) return BigDecimal.ZERO;
        BigDecimal totalMoney = unit.multiply(value);
        return totalMoney.subtract(buyMoney).divide(buyMoney, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));

    }

    public BigDecimal getTotalMoney() {
        return this.unit.multiply(this.value);
    }
}
